import express from 'express';
import bodyParser from 'body-parser';
import cookieParser from 'cookie-parser';
import cookieSession from 'cookie-session';
import uuid from 'uuid';
import consolidate from 'consolidate';  //模板引擎

import multer from 'multer';
import logger from 'morgan';

let multerObj=multer({dest:"./public/upload"});

let app=express();
app.listen(8080);

//中间键
app.use(multerObj.any());//允许所有文件上传
app.use(express.static("./public"));//静态资源服务器
app.use(logger("dev"));
app.use(logger("combined",{stream:require("fs").createWriteStream("./logs/logs.log",{flag:"a"})}));

app.use(bodyParser.urlencoded({extended:true,limit:'500mb'}));
app.use(bodyParser.json());
app.use(bodyParser.text());



app.use(cookieParser("cs1803"));
app.use(cookieSession({
	genid:function(){
		return uuid.v1();  
	},
	maxAge:20*1000*60,  
	secret:"cs1803"

}))



//模板引擎
app.set("view engine","html");
app.set("views","./views");
app.engine("html",consolidate.ejs);

//admin 路由
app.use("/admin",require("./route/admin/adminRouter"));


//index